window.addEventListener('DOMContentLoaded',function(){
  const A = document.querySelectorAll('.block-nav .nav .nav-center a')
  const ul = document.querySelector('.block-nav .nav .nav-center ul')
  const mains = document.querySelectorAll('.main')
  const content = document.querySelector('.content')

  function show(a, b) {
    //  给导航栏增加自定义属性
    for (let i = 0; i < a.length; i++) {
      a[i].dataset.index = i
    }
    // 使用事件委托为导航栏增加点击事件
    b.addEventListener('click', function (e) {
      if (e.target.tagName === 'A') {
         
        const index = e.target.dataset.index
        // 点击首页跳转页面
        if (index === '0') {
          location.href = './index.html'
        }
        // 点击别的就给首页内容隐藏显示出对应的盒子并让页面滚动到顶部
        content.classList.add('hide')
        mains.forEach(function (e) {
          e.classList.add('hide')
          mains[index - 1].classList.remove('hide')
        })
        document.documentElement.scrollTop = 0

      }
    })
  }
  show(A, ul)

  const a = document.querySelectorAll('.none-nav .nav .nav-center a')
  const UL = document.querySelector('.none-nav .nav .nav-center ul')
  // 隐藏导航栏的tab切换
  show(a, UL)
  //  获取本地数据
  const num = localStorage.getItem('name')

  if (num === '0') {
    content.classList.remove('hide')
  }
  else if (num) {
    content.classList.add('hide')
    mains[num - 1].classList.remove('hide')
    localStorage.removeItem('name')
  }




})
 